package com.erps.dao;

import java.util.Map;

import com.erps.CommonUtils.ActiveField;
import com.erps.CommonUtils.DateUtils;
import com.erps.CommonUtils.JActiveField;
import com.erps.CommonUtils.JActiveTable;
import com.erps.CommonUtils.Sequence;
import com.erps.CommonUtils.StringEx;
import com.erps.db.DBManager;
import com.hmkj.entity.ErspResPicture;

public class ErspResPictureDao extends JActiveTable {
	public ErspResPictureDao() {
		setDBTableName("ersp_res_picture");
		AddField(new JActiveField("id", "id", ActiveField.ftString, 36));
		setDefaultFieldValue("id", Sequence.getGuid());
		AddField(new JActiveField("res_id", "res_id", ActiveField.ftString, 200));
		AddField(new JActiveField("pic_path", "pic_path", ActiveField.ftString, 200));
		AddField(new JActiveField("pic_desc", "pic_desc", ActiveField.ftString, Integer.MAX_VALUE));

		AddField(new JActiveField("last_update_time", "last_update_time", ActiveField.ftLong));
		setDefaultFieldValue("last_update_time", String.valueOf(DateUtils.getDayTimeNum()));
		setDbKeyFields("id");
	}

	public int add(ErspResPicture vo) {
		setFieldValue("id", vo.getId());
		setFieldValue("res_id", vo.getRes_id());
		setFieldValue("pic_path", vo.getPic_path());
		setFieldValue("pic_desc", vo.getPic_desc());
		return DBManager.ExecSQL(this.getSQL());
	}

	public String getSQL(ErspResPicture vo) {
		setFieldValue("id", vo.getId());
		setFieldValue("res_id", vo.getRes_id());
		setFieldValue("pic_path", vo.getPic_path());
		setFieldValue("pic_desc", vo.getPic_desc());
		return this.getSQL();
	}

	public ErspResPicture FindLast(String cKeyID) {
		String cWhereParm = " res_id='" + cKeyID + "'";
		Map<String, String> vo = DBManager.GetRow(getQuerySQL(cWhereParm) + " order by last_update_time asc");
		if (vo != null) {
			ErspResPicture rs = new ErspResPicture();
			rs.setId(StringEx.getMapVal(vo, "id"));
			rs.setRes_id(StringEx.getMapVal(vo, "res_id"));
			rs.setPic_desc(StringEx.getMapVal(vo, "pic_desc"));
			rs.setPic_path(StringEx.getMapVal(vo, "pic_path"));
			rs.setLast_update_time(Long.parseLong(StringEx.getMapVal(vo, "last_update_time")));
			return rs;
		} else {
			return null;
		}
	}
}
